//
//  ByStoreCollectionVC.m
//  mijifen_ios
//
//  Created by mc on 2017/10/23.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByStoreCollectionVC.h"
// other
#import "ZKSegmentControl.h"

// view
#import "ByViewStoreConsume.h"
#import "ByViewStoreTimeConsume.h"
#import "ByViewStoreAcountTime.h"

// vc
#import "ByStoreCollectionWaitVC.h"
#import "ByStoreCollectionPaySuccessVC.h"

@interface ByStoreCollectionVC ()
@property (nonatomic, assign) NSInteger selectedIndex;
@end

@implementation ByStoreCollectionVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"储值卡收款";
    [self addLeftBackBarButtonItem];
    [self createViews];
    
    // 测试
    [self addBYItemviews:@[@"确认",@"支付完成"] mode:ByNavigationItemModeText position:ByNavigationItemPositionModeRight];
}

- (void)rightItemsAction:(NSInteger)rightIndex{
    if (rightIndex == 0) {
        ByStoreCollectionWaitVC *vc = [[ByStoreCollectionWaitVC alloc] init];
        [self by_normalPush:vc hasNavi:YES];
    }else{
        ByStoreCollectionPaySuccessVC *vc = [[ByStoreCollectionPaySuccessVC alloc] init];
        [self by_normalPush:vc hasNavi:YES];
    }
}

#pragma mark -
- (void)createViews{
    ZKSegmentControl *control = [[ZKSegmentControl alloc] init];
    [self.view addSubview:control];
    [control mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        if (@available(iOS 11.0,*)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(- 50);
        }else{
            make.top.equalTo(self.view.mas_top);
            make.bottom.mas_equalTo(self.view.mas_bottom).offset(- 50);
        }
    }];
    control.segmentsArray = @[@"储值消费",@"按次消费",@"计时消费"];
    control.segmentSelectTint = BY_TEXT_COLOR;
    control.backgroundColor = BY_TABLE_COLOR;
    
    control.dynamicalAddContentViewBlock = ^(void (^contentViewFetchBlock)(ZKSegmentContentView *contentView), NSInteger selectedIndex) {
        self.selectedIndex = selectedIndex;
        if (selectedIndex == 0) {
            ByViewStoreConsume *storeTable = [[ByViewStoreConsume alloc] init];
            if (contentViewFetchBlock) {
                contentViewFetchBlock(storeTable);
            }
        }
        else if(selectedIndex == 1){
            ByViewStoreTimeConsume *timeTable = [[ByViewStoreTimeConsume alloc] init];
            if (contentViewFetchBlock) {
                contentViewFetchBlock(timeTable);
            }
        }else{
            ByViewStoreAcountTime *accountTable = [[ByViewStoreAcountTime alloc] init];
            if (contentViewFetchBlock) {
                contentViewFetchBlock(accountTable);
            }
        }
    };
    
    // 底部确认
    UIButton *sureButton = [[UIButton alloc] init];
    [self.view addSubview:sureButton];
    [sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 50));
        if (@available(iOS 11.0,*)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        }else{
            make.bottom.equalTo(self.view.mas_bottom);
        }
    }];
    [sureButton setTitle:@"确认" forState:UIControlStateNormal];
    [sureButton setTitleColor:BY_TEXT_COLOR forState:UIControlStateNormal];
    [sureButton setBackgroundColor:BY_THEME_COLOR];
    [sureButton addTarget:self action:@selector(sureAction:) forControlEvents:UIControlEventTouchUpInside];
}
#pragma mark -
- (void)sureAction:(UIButton *)button{
    // 储值消费
    if (self.selectedIndex == 0) {
        
    }
    // 按次消费
    else if (self.selectedIndex == 1){
        
    }
    // 计时消费
    else{
        
    }
}



@end
